package com.apexbrain.apexbrainserver.mapper;

import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Insert;

/**
 * 对战表tb_user_in_battle的mapper
 */
@Mapper
public interface UserInBattleMapper
{
    /**
     * 获得当前用户对战的用户
     * @param userId 用户的用户名
     * @return 对战的对手
     */
    @Select("select user_id1 from tb_user_in_battle where user_id2 = ${userId}")
    String getBattleUser(String userId);

    /**
     * 新增对战用户
     * @param userId1 对战用户1
     * @param userId2 对战用户2
     * @return 新增是否成功
     */
    @Insert("insert into tb_user_in_battle values(${userId1}, ${userId2});\n" +
            "insert into tb_user_in_battle values(${userId2}, ${userId1});")
    boolean addUserIntoBattle(String userId1, String userId2);

    /**
     * 删除对战用户
     * @param userId 要删除的对战用户
     * @return 删除是否成功
     */
    @Delete("delete from tb_user_in_battle where user_id1 = ${userId} or user_id2 = ${userId}")
    boolean removeUser(String userId);
}
